<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/06/02
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 收货地址管理
 * @package app\erp\model
 */
class UcMemberReceivingAddress extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_member_receiving_address';

    /**
     * 添加数据
     * @param user_title 	        string  收件人
     * @param user_address 		    string  收货地址
     * @param user_mobile 		    int		电话
     * @param is_common 		    int     是否常用
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
    public function addData($user_id, $user_title, $user_city, $user_address, $user_mobile, $is_common){
        $data['user_title']     = $user_title;
        $data['user_city']   	= $user_city;
        $data['user_address']   = $user_address;
        $data['user_mobile']   	= $user_mobile;
        $data['is_common'] 		= $is_common;
        $data['uid']       		= $user_id;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	
	/**
     * 编辑数据
     * @param id 	                string  id
     * @param user_title 	        string  收件人
     * @param user_address 		    string  收货地址
     * @param user_mobile 		    int		电话
     * @param is_common 		    int     是否常用
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
	public function editData($id, $user_title, $user_city, $user_address, $user_mobile, $is_common){
		$map = [];
		$map['id'] = $id;
		
		$data = [];
		$data['user_title']     = $user_title;
        $data['user_city']   	= $user_city;
        $data['user_address']   = $user_address;
        $data['user_mobile']   	= $user_mobile;
        $data['is_common'] 		= $is_common;

        $res = $this ->update($data, $map);

		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author shiqiang
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
